package com.easyboot.web.system.controller;

import cn.hutool.core.date.DateUtil;
import com.easyboot.framework.domain.DataTableDto;
import com.easyboot.framework.core.ActionResult;
import com.easyboot.framework.core.BaseController;
import com.easyboot.framework.core.RequestHelper;
import com.easyboot.web.system.service.SysLogService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Date;

/**
 * @author yushuo
 * @className
 * @descripton TODO
 * @date 2021/6/25 13:01
 **/


@RequestMapping("/admin/syslog")
@Controller
public class SysLogController extends BaseController {

    @Autowired
    private RequestHelper requestHelper;
     @Autowired
     private SysLogService sysLogService;

    /**
     * @author yushuo
     * @description 首页
     * @date 13:03 2021/6/25
     * @param []
     * @return com.easyboot.framework.web.ActionResult
    **/
    @RequiresPermissions("admin:syslog:view")
    @GetMapping("/index")
    public ActionResult index(ModelMap model) {

        String now=DateUtil.format(new Date(),"yyyy-MM-dd");
        model.addAttribute("nowTime",now);
        return view();
    }

    /**
    *
     * @author yushuo
     * @description 数据列表
     * @date 13:03 2021/6/25
     * @param [dto]
     * @return com.easyboot.framework.web.ActionResult
    **/
    @RequiresPermissions("admin:syslog:view")
    @PostMapping("/getPageList")
    public ActionResult getPageList(DataTableDto dto){

        int logType=requestHelper.getInt("logType",0);
        String logTitle=requestHelper.getString("logTitle","");
        String logDate=requestHelper.getString("logDate","");
        DataTableDto data= sysLogService.getList(dto,logTitle,logType, DateUtil.parse(logDate,"yyyy-MM-dd"));
        return json(data);
    }

    /**
    *
     * @author yushuo
     * @description 删除日志
     * @date 13:29 2021/6/25
     * @param [ids]
     * @return com.easyboot.framework.web.ActionResult
    **/
    @RequiresPermissions("admin:syslog:delete")
    @GetMapping("/removeAll")
    public  ActionResult removeAll(String ids){
        sysLogService.removeAll(ids);
        return ok("数据已删除");
    }


    /**
    *
     * @author yushuo
     * @description 清空日志信息
     * @date 13:31 2021/6/25
     * @param []
     * @return com.easyboot.framework.web.ActionResult
    **/
    @RequiresPermissions("admin:syslog:clear")
    @GetMapping("/clearAll")
    public  ActionResult clearAll(){
        sysLogService.clearAll();
        return ok("数据已删除");
    }
}
